/*!
 * \file __list_node_priority_find.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "frlist.h"
#include "frproto_mng.h"
#include "apmtest_cunit.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{
//    frmodule_mng_init();
    return 0;
}

static int __suite_cleanup(void)
{
//    frmodule_mng_destory();
    return 0;
}


typedef struct __st_proto_priority {
    u_short us_port_start;      /* port 开始 */
    u_short us_port_end;        /* port 结束 */

    Frmodule_mng *p_module_mng;
} Frproto_priority;

int __list_node_priority_find(Frlist_node *p_st_node, const void *p_compare_data);
void __list_node_priority_free(Frlist_node *p_st_node);

static void __case1(void)
{
    Frlist_node *p_st_node = NULL;
    Frproto_priority *p_st_pri = NULL, *p_st_pri_cmp = NULL;
    int i_ret = 0;
    Frmodule_mng *p_module_mng = NULL;
    Frmodule_mng *p_module_mng_cmp = NULL;

    //p_st_node
    //p_module_mng
    p_module_mng = (Frmodule_mng *)frmalloc(sizeof(Frmodule_mng));
    memset(p_module_mng,0x00, sizeof(Frmodule_mng));
    p_module_mng->p_st_l7_module = (L7_module *)frmalloc(sizeof(L7_module));
    memset(p_module_mng->p_st_l7_module ,0x00, sizeof(L7_module));
    p_module_mng->p_st_l7_module->i_l7_proto = 1;

    //p_st_pri
    p_st_pri = (Frproto_priority *)frmalloc(sizeof(Frproto_priority));
    memset(p_st_pri, 0x00, sizeof(Frproto_priority));
    p_st_pri->us_port_start = 40;
    p_st_pri->us_port_end = 80;
    p_st_pri->p_module_mng = p_module_mng;

    //p_st_node
    p_st_node = frlist_node_create(p_st_pri);

    //p_st_pri_cmp
    //p_module_mng_cmp
    p_module_mng_cmp = (Frmodule_mng *)frmalloc(sizeof(Frmodule_mng));
    memset(p_module_mng_cmp,0x00, sizeof(Frmodule_mng));
    p_module_mng_cmp->p_st_l7_module = (L7_module *)frmalloc(sizeof(L7_module));
    memset(p_module_mng_cmp->p_st_l7_module ,0x00, sizeof(L7_module));
    p_module_mng_cmp->p_st_l7_module->i_l7_proto = 1;

    //p_st_pri_cmp
    p_st_pri_cmp = (Frproto_priority *)frmalloc(sizeof(Frproto_priority));
    memset(p_st_pri_cmp, 0x00, sizeof(Frproto_priority));
    p_st_pri_cmp->us_port_start = 50;
    p_st_pri_cmp->us_port_end = 100;
    p_st_pri_cmp->p_module_mng = p_module_mng_cmp;

    i_ret = __list_node_priority_find(p_st_node, p_st_pri_cmp);

//    CU_ASSERT_EQUAL(i_ret, 0);

    __list_node_priority_free(p_st_node);
    frfree(p_st_node);
    frfree(p_module_mng->p_st_l7_module);
    frfree(p_module_mng);
    frfree(p_st_pri_cmp);
    frfree(p_module_mng_cmp->p_st_l7_module);
    frfree(p_module_mng_cmp);
    return;

}

static void __case2(void)
{
    Frlist_node *p_st_node = NULL;
    Frproto_priority *p_st_pri = NULL, *p_st_pri_cmp = NULL;
    int i_ret = 0;
    Frmodule_mng *p_module_mng = NULL;
    Frmodule_mng *p_module_mng_cmp = NULL;

    //p_st_node
    //p_module_mng
    p_module_mng = (Frmodule_mng *)frmalloc(sizeof(Frmodule_mng));
    memset(p_module_mng,0x00, sizeof(Frmodule_mng));
    p_module_mng->p_st_l7_module = (L7_module *)frmalloc(sizeof(L7_module));
    memset(p_module_mng->p_st_l7_module ,0x00, sizeof(L7_module));
    p_module_mng->p_st_l7_module->i_l7_proto = 1;

    //p_st_pri
    p_st_pri = (Frproto_priority *)frmalloc(sizeof(Frproto_priority));
    memset(p_st_pri, 0x00, sizeof(Frproto_priority));
    p_st_pri->us_port_start = 40;
    p_st_pri->us_port_end = 80;
    p_st_pri->p_module_mng = p_module_mng;

    //p_st_node
    p_st_node = frlist_node_create(p_st_pri);

    //p_st_pri_cmp
    //p_module_mng_cmp
    p_module_mng_cmp = (Frmodule_mng *)frmalloc(sizeof(Frmodule_mng));
    memset(p_module_mng_cmp,0x00, sizeof(Frmodule_mng));
    p_module_mng_cmp->p_st_l7_module = (L7_module *)frmalloc(sizeof(L7_module));
    memset(p_module_mng_cmp->p_st_l7_module ,0x00, sizeof(L7_module));
    p_module_mng_cmp->p_st_l7_module->i_l7_proto = 2;

    //p_st_pri_cmp
    p_st_pri_cmp = (Frproto_priority *)frmalloc(sizeof(Frproto_priority));
    memset(p_st_pri_cmp, 0x00, sizeof(Frproto_priority));
    p_st_pri_cmp->us_port_start = 10;
    p_st_pri_cmp->us_port_end = 60;
    p_st_pri_cmp->p_module_mng = p_module_mng_cmp;

    i_ret = __list_node_priority_find(p_st_node, p_st_pri_cmp);

//    CU_ASSERT_EQUAL(i_ret, 0);

    __list_node_priority_free(p_st_node);
    frfree(p_st_node);
    frfree(p_module_mng->p_st_l7_module);
    frfree(p_module_mng);
    frfree(p_module_mng_cmp->p_st_l7_module);
    frfree(p_module_mng_cmp);
    frfree(p_st_pri_cmp);
    return;

}

static void __case3(void)
{
    Frlist_node *p_st_node = NULL;
    Frproto_priority *p_st_pri = NULL, *p_st_pri_cmp = NULL;
    int i_ret = 0;
    Frmodule_mng *p_module_mng = NULL;
    Frmodule_mng *p_module_mng_cmp = NULL;

    //p_st_node
    //p_module_mng
    p_module_mng = (Frmodule_mng *)frmalloc(sizeof(Frmodule_mng));
    memset(p_module_mng,0x00, sizeof(Frmodule_mng));
    p_module_mng->p_st_l7_module = (L7_module *)frmalloc(sizeof(L7_module));
    memset(p_module_mng->p_st_l7_module ,0x00, sizeof(L7_module));
    p_module_mng->p_st_l7_module->i_l7_proto = 1;

    //p_st_pri
    p_st_pri = (Frproto_priority *)frmalloc(sizeof(Frproto_priority));
    memset(p_st_pri, 0x00, sizeof(Frproto_priority));
    p_st_pri->us_port_start = 40;
    p_st_pri->us_port_end = 80;
    p_st_pri->p_module_mng = p_module_mng;

    //p_st_node
    p_st_node = frlist_node_create(p_st_pri);

    //p_st_pri_cmp
    p_st_pri_cmp = (Frproto_priority *)frmalloc(sizeof(Frproto_priority));
    memset(p_st_pri_cmp, 0x00, sizeof(Frproto_priority));
    p_st_pri_cmp->us_port_start = 10;
    p_st_pri_cmp->us_port_end = 60;
    p_st_pri_cmp->p_module_mng = p_module_mng_cmp;

    i_ret = __list_node_priority_find(p_st_node, p_st_pri_cmp);

    CU_ASSERT_EQUAL(i_ret, 1);

    __list_node_priority_free(p_st_node);
    frfree(p_st_node);
    frfree(p_module_mng->p_st_l7_module);
    frfree(p_module_mng);
    frfree(p_st_pri_cmp);
    frfree(p_module_mng_cmp);
    return;

}

static void __case4(void)
{
    Frlist_node *p_st_node = NULL;
    Frproto_priority *p_st_pri = NULL, *p_st_pri_cmp = NULL;
    int i_ret = 0;
    Frmodule_mng *p_module_mng = NULL;
    Frmodule_mng *p_module_mng_cmp = NULL;

    //p_st_node
    //p_module_mng
    p_module_mng = (Frmodule_mng *)frmalloc(sizeof(Frmodule_mng));
    memset(p_module_mng,0x00, sizeof(Frmodule_mng));
    p_module_mng->p_st_l7_module = (L7_module *)frmalloc(sizeof(L7_module));
    memset(p_module_mng->p_st_l7_module ,0x00, sizeof(L7_module));
    p_module_mng->p_st_l7_module->i_l7_proto = 1;

    //p_st_pri
    p_st_pri = (Frproto_priority *)frmalloc(sizeof(Frproto_priority));
    memset(p_st_pri, 0x00, sizeof(Frproto_priority));
    p_st_pri->us_port_start = 40;
    p_st_pri->us_port_end = 80;
    p_st_pri->p_module_mng = p_module_mng;

    //p_st_node
    p_st_node = frlist_node_create(p_st_pri);

    //p_st_pri_cmp
    //p_module_mng_cmp
    p_module_mng_cmp = (Frmodule_mng *)frmalloc(sizeof(Frmodule_mng));
    memset(p_module_mng_cmp,0x00, sizeof(Frmodule_mng));
    p_module_mng_cmp->p_st_l7_module = (L7_module *)frmalloc(sizeof(L7_module));
    memset(p_module_mng_cmp->p_st_l7_module ,0x00, sizeof(L7_module));
    p_module_mng_cmp->p_st_l7_module->i_l7_proto = 2;

    //p_st_pri_cmp
    p_st_pri_cmp = (Frproto_priority *)frmalloc(sizeof(Frproto_priority));
    memset(p_st_pri_cmp, 0x00, sizeof(Frproto_priority));
    p_st_pri_cmp->us_port_start = 10;
    p_st_pri_cmp->us_port_end = 60;
    p_st_pri_cmp->p_module_mng = p_module_mng_cmp;

    i_ret = __list_node_priority_find(p_st_node, p_st_pri_cmp);

    CU_ASSERT_EQUAL(i_ret, 1);

    __list_node_priority_free(p_st_node);
    frfree(p_st_node);
    frfree(p_module_mng->p_st_l7_module);
    frfree(p_module_mng);
    frfree(p_module_mng_cmp->p_st_l7_module);
    frfree(p_module_mng_cmp);
    frfree(p_st_pri_cmp);
    return;

}


int add_suite___list_node_priority_find(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frproto_mng __list_node_priority_find()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);
    CU_add_test(pSuite, "case4", __case4);
//    CU_add_test(pSuite, "case5", __case5);

    return FR_SUCC;
}
